﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProjectCore.Application;
using ProjectCore.Common;
using ProjectCore.Domain.Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ProjectCore.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class EvalController : ControllerBase
    {
        private readonly IAppEval appEval;
        public EvalController(IAppEval _appAdmin)
        {
            appEval = _appAdmin;
        }
        /// <summary>
        /// 获取评论表集合
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetEvals(int pageIndex, int pageSize)
        {
            Task<HeaderResult<List<Eval>>> evals = appEval.GetEvals(pageIndex,pageSize);
            return Ok(await evals);
        }


        /// <summary>
        /// 评论表逻辑删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> IsDel(int Id)
        {
            Task<int> n = appEval.IsDel(Id);
            return Ok(new { data = await n });
        }


        /// <summary>
        /// 获取评论数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetEval(int Id)
        {
            Task<Eval> eval = appEval.GetEval(Id);
            return Ok(new { data = await eval });
        }


        /// <summary>
        ///  评论修改
        /// </summary>
        /// <param name="eval"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> UptEval(Eval eval)
        {
            Task<int> n = appEval.UptEval(eval);
            return Ok(new { data = await n });
        }
    }
}
